#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N = 2e5 + 10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
int main()
{
    close();

    string s1, s2;
    cin >> s1 >> s2;

    for (int i = 0; i < s1.size(); i++)
    {
        if (i == 0 && s1[i] == '1') continue;
        string s3 = s1;
        if (s3[i] == '1') s3[i] = '0';
        else s3[i] = '1';

        //int t1 = stoi(s3);
        int num1 = 0;
        int n = s1.size();
        for (int j = 0; j < n; j++)
        {
            if (s3[j] == '1') num1 +=pow(2, n - 1 - j);
        }


        for (int j = 0; j < s2.size(); j++)
        {
            for (int jj = 0; jj <= 2; jj++)
            {
                //if (j == 0 && jj == 0) continue;
                string s4 = s2;
                if ((int)(s4[j]-'0') == jj) continue;

                s4[j] = '0' + jj;
                int num2 = 0;
                int m = s2.size();
                for (int k = 0; k < m; k++)
                {
                    int t = (int)(s4[k]-'0');
                    if (s4[k] == '1'|| s4[k] == '2') num2 +=t*pow(3, m - 1 - k);
                }

                if (num1 == num2)
                {
                    cout << num1 << '\n';
                    // cout<<s3<<'\n';
                    // cout<<s4<<'\n';
                    return 0;
                }
            }

        }
    }

    cout<<0<<'\n';

    return 0;
}
